package com.zmv.buzzmeback;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

public class KeypadAdapter extends BaseAdapter {
	// Declare button click listener variable
	private OnClickListener mOnButtonClick;

	// Method to set button click listener variable
	public void setOnButtonClickListener(OnClickListener listener) {
		mOnButtonClick = listener;
	}

	private Context mContext;

	public KeypadAdapter(Context c) {
		mContext = c;
	}

	public int getCount() {
		return mButtons.length;
	}

	public Object getItem(int position) {
		return mButtons[position];
	}

	public long getItemId(int position) {
		return 0;
	}

	// create a new ButtonView for each item referenced by the Adapter
	public View getView(int position, View convertView, ViewGroup parent) {
		Button btn;
		if (convertView == null) { // if it's not recycled, initialize some
									// attributes
			btn = new Button(mContext);
			KeypadButton keypadButton = mButtons[position];
			btn.setOnClickListener(mOnButtonClick);
			// Set CalculatorButton enumeration as tag of the button so that we
			// will use this information from our main view to identify what to
			// do
			btn.setTag(keypadButton);
		} else {
			btn = (Button) convertView;
		}
		btn.setHeight(157);
		btn.setText(mButtons[position].getText());
		return btn;
	}

	// Create and populate keypad buttons array with CalculatorButton values
	private KeypadButton[] mButtons = { KeypadButton.ONE, KeypadButton.TWO,
			KeypadButton.THREE, KeypadButton.FOUR, KeypadButton.FIVE,
			KeypadButton.SIX, KeypadButton.SEVEN, KeypadButton.EIGHT,
			KeypadButton.NINE, KeypadButton.CALL, KeypadButton.ZERO,
			KeypadButton.DELETE };
}